home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / dev / lang / Python16_Src.lha / Python16_Source / Python / fmod.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-03  |  432 b   |  27 lines

  1. /* Portable fmod(x, y) implementation for systems that don't have it */
  2.  
  3. #include "config.h"
  4.  
  5. #include "mymath.h"
  6. #include <errno.h>
  7.  
  8. double
  9. fmod(double x, double y)
  10. {
  11.     double i, f;
  12.     
  13.     if (y == 0.0) {
  14.         errno = EDOM;
  15.         return 0.0;
  16.     }
  17.     
  18.     /* return f such that x = i*y + f for some integer i
  19.        such that |f| < |y| and f has the same sign as x */
  20.     
  21.     i = floor(x/y);
  22.     f = x - i*y;
  23.     if ((x < 0.0) != (y < 0.0))
  24.         f = f-y;
  25.     return f;
  26. }
  27.